package pt.iscte.daam.ejb;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.log4j.Logger;

import pt.iscte.daam.model.Senhorio;

@Stateless
@LocalBean
@Path("/customers")
public class CustomerService {
	
	private static final Logger logger = Logger.getLogger(Senhorio.class);

	@PersistenceContext(unitName = "CustomerService", type = PersistenceContextType.TRANSACTION)
	EntityManager entityManager;

	@GET
	@Produces({
	//MediaType.APPLICATION_XML,
	MediaType.APPLICATION_JSON })
	@Path("{id}")
	public Senhorio read(@PathParam("id") String id) {
		Senhorio customer = new Senhorio();
		
		Senhorio find = null;
		try {
			find = entityManager.find(Senhorio.class, id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (find != null) {
			logger.debug("Retornei: "+find);
			return find;
		}
			
		return customer;
	}

}